// pages/bookStore/bookStore.js
var businessLogic = require('../../../utils/NetWork/Model/BookbusinessLogic.js')
var common = require('../../../utils/common.js')

//第一步业务逻辑层
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curNavId: 0,
    banjiid: 0,
    kemuid: 0,
    banbenid: 0,
    ur: '',
    title:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let c = common.Getorgid();
    this.setData({
      orgid: c.orgid,
      userid: c.userid,
    });
    this.bookList();
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.close();
    this.bookList();
  },
  close: function () {
    this.ConditionList = this.selectComponent("#ConditionList");
    this.ConditionList.close();
    this.shanxuan();
  
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
  , isShow: function (e) {
    this.ConditionList.isShow();
    this.bookList();
  },
  isShow2: function (e) {
    if (this.data.show == true) {
      this.setData({
        show: false,
      })
    }
  },
  isSelect: function (e) {
    let id = e.currentTarget.dataset.id;
    console.log(id)
  /*   this.setData({
      curNavId: id,
    }) */
  },
  detail: function (e) {
    var id = e.currentTarget.dataset.id
    var url = '../bookDetail/bookDetail?id=' + id;
    wx.navigateTo({
      url: url,
      success: function (res) {
        // success
      },
      fail: function () {
        // fail
      },
      complete: function () {
        // complete
      }
    })
  },
  //筛选
  shanxuan: function (ur) {
    if(ur==''||ur==undefined){
      var ur='';
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur":ur } 
    businessLogic.getCondition(params, (res) => {
      //渲染页面
      this.ConditionList.conditionList(res, ur);
    })
    }else{
      console.log(ur.detail)
      let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": ur.detail[0] }
      businessLogic.getCondition(params, (res) => {
       //渲染页面
       this.setData({
         ur:ur.detail[0]
       })
        this.ConditionList.conditionList(res, ur.detail[0]);
    
      })
    }
  },
 bookList: function () {
   common.showLoading("加载中", "loading");
    // 第二步 传参
   let params = { "orgid": this.data.orgid, "userid": this.data.userid, "page": 1, "num": 1000, "ur": this.data.ur, searchField: "title,orgid", "searchValue": this.data.title + "," + this.data.orgid }
    //第三步 调用接口
    businessLogic.BookList(params, (res) => {
      //console.log("书本列表",res); 
      //第五步 把获取的值，传入data
      this.setData({
        bookList: res
      });
    });
  },
 bindKeyInput: function (e) {
   this.setData({
     title: e.detail.value
   })
 },
  search2: function (e) {
    let params = { "orgid": this.data.orgid, "userid": this.data.userid, "ur": this.data.ur, searchField: "title,orgid", "searchValue": this.data.title + "," + this.data.orgid }
    businessLogic.BookList(params, (res) => {
      //console.log(res)
      this.setData({
        bookList: res,
      });
    });
  },
  // 这边要注册组件
  onReady: function () {
    //ConditionList
    this.ConditionList = this.selectComponent("#ConditionList");
  },
})